<!doctype html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="description" content="">
  <meta name="keywords" content="">
  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
  <title>长安整车物流</title>
  <link rel="stylesheet" href="css/base.css">
  <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/1.1.2/weui.min.css">
  <script src="https://cdn.bootcss.com/zepto/1.2.0/zepto.min.js"></script>
  <script src="https://res.wx.qq.com/open/libs/weuijs/1.1.3/weui.min.js"></script>
  <script src="js/api.js"></script>
  <script src="js/wx.js"></script>
</head>

<body>
  <div>
    <div class="weui-panel">
      <form id="form" action="">
        <div class="weui-cells__title">驾驶员注册</div>
        <div class="weui-cells">
          <div class="weui-cell">
            <div class="weui-cell__hd">
              <label for="driverName" class="weui-label">姓名</label>
            </div>
            <div class="weui-cell__bd">
              <input class="weui-input" id="driverName" required type="text" value="" placeholder="请输入姓名" />
            </div>
          </div>

          <div class="weui-cell">
            <div class="weui-cell__hd">
              <label for="tel" class="weui-label">手机</label>
            </div>
            <div class="weui-cell__bd">
              <input class="weui-input" id="tel" required pattern="^1[1,3,4,5,6,7,8][0-9]{9}$" type="number" value="" placeholder="请输入手机"
                notMatchTips="手机号格式错误" />
            </div>
          </div>
        </div>

        <div class="weui-btn-area weui-flex">
          <span class="weui-flex__item">
            <!--<a class="weui-btn weui-btn_primary" onclick="submit()" href="javascript:">确定</a>-->
            <a class="weui-btn weui-btn_primary" id="submit" href="javascript:">确定</a>
          </span>
          <span style="margin-left: 16px">
            <a class="weui-btn weui-btn_default" id="reset" href="javascript:;">重置</a>
          </span>
        </div>
      </form>
    </div>
  </div>
  <script>
    function submit() {
      weui.form.checkIfBlur('#form');
      weui.form.validate('#form', function (error) {
        if (!error) {
          var params = {
            driverName: $('#driverName').val(),
            tel: $('#tel').val()
          }
          bind(params, function(data) {
            window.localStorage.setItem('driverId', data.detail.driverId)
            weui.toast('绑定成功', 3000);
          })
        }
        // return true; // 当return true时，不会显示错误
      });
    }

    function reset() {
      $('#driverName').val('')
      $('#tel').val('')
    }
    $("#submit").on('click',submit);
    $("#reset").on('click',reset);
  </script>
</body>

</html>